package com.typy.www.tpay.ui.itemview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.typy.www.tpay.R;
import com.typy.www.tpay.bean.vm.BuyVm;
import com.typy.www.tpay.ui.acitivity.ActivicationActivity;
import com.typy.www.tpay.ui.view.CircleImageView;
import com.typy.www.tpay.util.ClassHoldUtil;
import com.typy.www.tpay.util.ToastUtil;
import com.typy.www.tpay.util.UpdataUiUtil;
import com.zhy.android.percent.support.PercentLinearLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 13799 on 2018/7/12.
 */

public class DigiBuyItem {
    View mView;
    ViewHolder holder;
    private Context mContext;

    public DigiBuyItem(Context context) {
        mContext = context;
        mView = LayoutInflater.from(context).inflate(R.layout.item_digi_detail_buy, null);
        holder = new ViewHolder(mView);
    }

    public View getView() {
        return mView;
    }

    public void bind(final BuyVm vm, final int position, final boolean isBuy, final String fdName, final String fdSeqNo) {
        if (vm != null) {
            UpdataUiUtil.getDefaul().setText(vm.getFdNickName(), holder.tvNickname)
                    .setText("¥" + vm.getFdPrice(), holder.tvPrice)
                    .setText("限额：" + vm.getFdRemainQuantity(), holder.tvLimit);

        }
        if (isBuy)
            holder.tvJiaoyi.setText("购买");
        else
            holder.tvJiaoyi.setText("出售");

        holder.llJiaoyi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isBuy)
                    ActivicationActivity.show(mContext, ClassHoldUtil.BUYFROM, vm.getFdNickName(),vm.getFdRemainQuantity(),vm.getFdPrice(),fdName,fdSeqNo,vm.getFdId());
                else
                    ActivicationActivity.show(mContext, ClassHoldUtil.SELLFROM, vm.getFdNickName(),vm.getFdRemainQuantity(),vm.getFdPrice(),fdName,fdSeqNo,vm.getFdId());
            }
        });
    }

    static class ViewHolder {
        @BindView(R.id.img_touxian)
        CircleImageView imgTouxian;
        @BindView(R.id.tv_nickname)
        TextView tvNickname;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_limit)
        TextView tvLimit;
        @BindView(R.id.tv_jiaoyi)
        TextView tvJiaoyi;
        @BindView(R.id.ll_jiaoyi)
        LinearLayout llJiaoyi;
        @BindView(R.id.img_div)
        ImageView imgDiv;
        @BindView(R.id.ll_touxian)
        PercentLinearLayout llTouxian;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
